package com.example.home.viewmodel;

import android.util.Log;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.example.common.component.GameCtrlCom;
import com.example.common.control.ICallback;
import com.example.common.model.GameApiGameResp;
import com.example.home.model.Card;

import java.util.LinkedList;
import java.util.List;

public class HomeViewModel extends ViewModel {
    private static final String TAG = "HomeViewModel";
    // TODO: Implement the ViewModel
    private GameCtrlCom gameCtrlCom;//游戏网络模块

    private MutableLiveData<Integer> isActive=new MutableLiveData<>();//3个fragment的active状态
    private MutableLiveData<LinkedList<Card>> cards=new MutableLiveData<>();//卡片数据
    private MutableLiveData<Integer> toWhich=new MutableLiveData<>();//页面滑动到哪个Holder

    private MutableLiveData<LinkedList<Card>> preonlineCards=new MutableLiveData<>();//即将上线页面的卡片数据

    private MutableLiveData<List<GameApiGameResp>> leaderboardGames=new MutableLiveData<>();//排行榜游戏数据——正式使用

    private MutableLiveData<String> remainMsg=new MutableLiveData<>();//提示信息

    private MutableLiveData<Integer> loadFinish=new MutableLiveData<>();//第几个刷新完成了的

    public HomeViewModel(){
        gameCtrlCom=new GameCtrlCom();
        //加载数据
        init();
    }

    private void init(){
        cards.setValue(new LinkedList<>());
        preonlineCards.setValue(new LinkedList<>());
        //加载排行榜
        loadLeaderboardList();
    }

    /**
     *排行榜游戏数据加载
     */
    public void loadLeaderboardList(){
        //开始获取排行榜
        gameCtrlCom.getGame(new ICallback() {
            @Override
            public void onSuccess(Object response) {
                if(response==null){
                    return;
                }
                leaderboardGames.setValue((List<GameApiGameResp>)response);
            }

            @Override
            public void onFailed(String mes) {
                Log.i(TAG, "onFailed: "+mes);
            }
        });
    }




    public MutableLiveData<LinkedList<Card>> getCards() {
        return cards;
    }

    public MutableLiveData<LinkedList<Card>> getPreonlineCards() {
        return preonlineCards;
    }

    public MutableLiveData<Integer> getIsActive() {
        return isActive;
    }

    public void setIsActive(MutableLiveData<Integer> isActive) {
        this.isActive = isActive;
    }

    public MutableLiveData<List<GameApiGameResp>> getLeaderboardGames() {
        return leaderboardGames;
    }

    public MutableLiveData<String> getRemainMsg() {
        return remainMsg;
    }

    public MutableLiveData<Integer> getToWhich() {
        return toWhich;
    }

    public MutableLiveData<Integer> getLoadFinish() {
        return loadFinish;
    }
}